<template>
	<view class="content">
		<view class="xuaz" @click="copyUrl()">
			<view class="lable-name" style="width: 20%;">钱包网络</view>
			<view class="lable-select" style="width: 80%;">
				<input type="text" v-model="wallet_info.wallet_net" style="font-size: 14px;" disabled="disabled"/>
			</view>
		</view>
		<view class="xuaz" @click="copyUrl()">
			<view class="lable-name" style="width: 20%;">钱包地址</view>
			<view class="lable-select" style="width: 80%;">
				<input type="text" v-model="wallet_info.wallet_address" style="font-size: 14px;" disabled="disabled"/>
			</view>
		</view>
		<text style="font-size: .8rem;color: #737e7ea3;">点击"钱包地址"位置自动复制钱包地址</text>
		
		<view class="xuaz">
			<view class="lable-name" style="width: 20%;">钱包二维码</view>
			<view class="lable-select" style="width: 80%;">
				<image :src="wallet_info.wallet_qrcode" style="width: 15rem;height: 30rem;"></image>
			</view>
		</view>
		
		<view class="xuaz">
			<view class="lable-name" style="width: 20%;">支付宝二维码</view>
			<view class="lable-select" style="width: 80%;">
				<image :src="wallet_info.zfb_qrcode" style="width: 15rem;height: 30rem;"></image>
			</view>
		</view>
		
		<view class="xuaz">
			<view class="lable-name" style="width: 20%;">微信二维码</view>
			<view class="lable-select" style="width: 80%;">
				<image :src="wallet_info.wx_qrcode" style="width: 15rem;height: 30rem;"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				wallet_info:{
					zfb_qrcode:null,
					wx_qrcode:null,
					wallet_address:null,
					wallet_qrcode:null,
					wallet_net:null,
				},
				userInfo:null,
				user_token:null
			}
		},
		onLoad() {
			this.getUserInfo()
			this.getSystemConfig()
		},
		methods: {
			copyUrl(){
				let url = this.wallet_info.wallet_address
				navigator.clipboard.writeText(url).then(function(){
					uni.showToast({
						icon:'none',
						title:'复制钱包地址成功'
					})
				})
			},
			getUserInfo(){
				let that = this
				if(that.userInfo == null){
					uni.getStorage({
						key: 'user_token',
						success: function (res) {
							that.user_token = res.data
							that.checkUser()
						},
						fail: function(res){
							uni.showToast({
								title:'请先登录',
								icon:'none',
								success() {
									uni.redirectTo({
										url:'/pages/login/login',
									})
								}
							})
							
						}
					});
				}
			},
			checkUser(){
				let that = this
				uni.request({
					url:getApp().globalData.baseUrl + '/api/user/getUserInfo',
					method:'POST',
					header: {token:that.user_token},
					success(res) {
						if(res.data.code == 401){
							uni.removeStorage({
								key:'user_token',
								success() {
									uni.showToast({
										icon:'none',
										title:'登录已失效,请重新登录',
										success() {
											setTimeout(function(){
												uni.redirectTo({
													url:'/pages/login/login'
												})
											})
										}
									})
								}
							})
						}
						that.userInfo = res.data.data
						console.log(that.userInfo)
						that.url = getApp().globalData.baseUrl + "/#/pages/register/register?agent_id="+that.userInfo.id
					},
					fail() {
						uni.showToast({
							title:'网络错误',
							icon:'none',
						})
					}
				})
			},
			getSystemConfig(){
				let that = this
				uni.request({
					url:getApp().globalData.baseUrl + '/api/index/getSystemConfig',
					header:{token: that.user_token},
					success(res) {
						that.wallet_info = res.data.data
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #f4f4f4;
	}
	.xuaz{
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 0 0.6rem;
		padding: 0.6rem;
		border-bottom: 1px solid #f6f6f6 !important;
	}
	.lable-name{
		width: 30%;
		font-weight: bold;
		font-size: 14px;
	}
	.lable-select{
		width: 60%;
		display: flex;
	}
	.content{
		background: #fff;
		display: flex;
		flex-direction: column;
		margin-top: .7rem;
	}
	
	.lable-select >input{
		width: 100%;
	}
</style>
